import { createRouter, createWebHistory } from 'vue-router'
import {useCounterStore} from '@/stores/index.js'
import Cookies from 'js-cookie'
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path:'/index',
      name:'index',
      component:()=>import('@/views/index/index.vue'),
      redirect:'/index/indexViews',
      children: [
        { 
        path: '/index/indexViews',
        name:'indexViews',
        component:()=>import('@/views/index/indexViews.vue'),
      },
      {
        path:'/index/particulars',
        name:'particulars',
        component:()=>import('@/views/about/particulars.vue'),
      },
      {
        path:'/index/addAdmin',
        name:'addAdmin',
        component:()=>import('@/views/about/addAdmin.vue'),
      }
      ],
    },
    {
      path:'/',
      name:'login',
      component:()=>import('@/views/login/bookLogin.vue')
    }
  ]
})
router.beforeEach((to) => { 
  const adminToken=Cookies.get('admin')
  if(!adminToken&& to.path!=='/'){
    return  '/' 
  }

})
export default router
